package com.hx.voice.recognition.admin.manager.controller;


import com.hx.voice.recognition.admin.manager.entity.Menu;
import com.hx.voice.recognition.admin.manager.entity.User;
import com.hx.voice.recognition.admin.manager.service.IMenuService;
import com.hx.voice.recognition.admin.manager.service.IUserService;
import com.hx.voice.recognition.admin.rpc.service.PermissionService;
import com.hx.voice.recognition.admin.vo.FrontUser;
import com.hx.voice.recognition.admin.vo.MenuTree;
import com.hx.voice.recognition.common.rest.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @descripe：
 * @company：南京华讯方舟通讯设备有限公司
 * @author：zhoujinbing
 * @time：2019-06-12
 * @version：V1.0
 */
@RestController
@Slf4j
@RequestMapping("user")
public class UserController extends BaseController<User> {

    @Autowired
    public IUserService iUserService;

    @Autowired
    protected HttpServletRequest request;

    @Autowired
    private PermissionService permissionService;

    @Autowired
    private IMenuService menuService;

    /**
     * @description  获取前台用户菜单以及操作按钮信息
     * @method  getUserInfo
     * @param  [token]
     * @return org.springframework.http.ResponseEntity<?>
     * @date: 2019/6/19 10:21
     * @author:zhoujinbing
     */
    @RequestMapping(value = "/front/info",method = RequestMethod.GET)
    public @ResponseBody ResponseEntity<?> getUserInfo(String token) throws Exception {
        FrontUser user = permissionService.getUserInfo(token);
        if(user == null)
        {
            return ResponseEntity.status(401).body(false);
        }
        return ResponseEntity.ok(user);
    }

    /**
     * @description 根据登录账号获取授权过的菜单
     * @method  getMenusByUsername
     * @param  [token]
     * @return java.util.List<com.hx.zjb.security.admin.vo.MenuTree>
     * @date: 2019/6/19 11:04
     * @author:zhoujinbing
     */
    @RequestMapping(value = "/front/menus",method = RequestMethod.GET)
    public @ResponseBody List<MenuTree> getMenusByUsername(String token) throws Exception{
        return permissionService.getMenusByUsername(token);
    }

    @RequestMapping(value = "/front/menu/all",method = RequestMethod.GET)
    public @ResponseBody List<Menu> getAllMenus()
    {
        return menuService.selectMenuList();
    }

}
